package org.example.service.serviceImpl;

import org.example.entity.Dept;
import org.example.mapper.DeptMapper;
import org.example.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.core.Local;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeptServiceImpl implements DeptService {
@Autowired
private DeptMapper deptMapper;
    @Override
    public List<Dept> listAll() {
            List<Dept> deptList =  deptMapper.selectAll();
        return deptList;
    }

    @Override
    public void deleteDeptById(Integer id) {
        deptMapper.deleteById(id);
    }

    @Override
    public void addDeptWithDept(Dept dept) {
    //创建dept对象  补充创建时间和修改时间
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());


        deptMapper.insertDept(dept);
    }

    @Override
    public Dept getInfo(Integer id) {
        Dept dept = deptMapper.selectById(id);
        return dept;
    }

    @Override
    public void update(Dept dept) {
//          设置部门信息更新时间
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.updateDept(dept);
    }
}
